package com.zsj.juc.jmm;



import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class ReorderDemo01 {
    //可以自己在这里尝试加与不加volatile的结果
    volatile static boolean flag = true;

    public static void main(String[] args) {
        new Thread(() -> {
            log.info(Thread.currentThread().getName() + "come in");
            while (flag) {
            }
            log.info(Thread.currentThread().getName() + "over");
        }, "t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            log.info(Thread.currentThread().getName() + "come in");
            flag = false;
            log.info(Thread.currentThread().getName() + "over");
        }, "t2").start();

    }
}
